﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LyricFinder;

namespace LyricFinderApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void runComponent()
        {
            listBox1.Items.Clear();
            richTextBox1.Text = "";
            LyricFinder.LyricComponent comp = new LyricComponent();
            string keyword = textBox1.Text;
            List<string> list = new List<string>();
            if (radioButton1.Checked)
            {
                list = comp.getList(keyword, 1);
            }
            else if (radioButton2.Checked)
            {
                list = comp.getListByArtist(keyword);
            }
            else if (radioButton3.Checked)
            {
                list = comp.getList(keyword, 3);
            }
            else if (radioButton4.Checked)
            {
                list = comp.getList(keyword, 4);
            }
            else if (radioButton5.Checked)
            {
                list = comp.getListByTags(keyword);
            }

            if (list.Count == 0)
            {
                MessageBox.Show("Your search " + keyword + " is not found");
            }
            else if (list[0].Equals("Cannot connect to www.songlyrics.com"))
            {
                MessageBox.Show("Cannot connect to www.songlyrics.com", "Connection Error");
            }
            else
            {
                for (int i = 0; i < list.Count; i++)
                {
                    listBox1.Items.Add(list[i]);
                }
            }
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            runComponent();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            richTextBox1.Text = "";
            LyricComponent comp = new LyricComponent();
            string lyric = comp.getLyric(listBox1.SelectedItem.ToString());
            richTextBox1.Text = lyric;
        }
    }
}
